package com.lzy.product.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import com.lzy.product.dao.AgentProductMapperExt;
import com.lzy.product.dtos.agent.AgentProductDto;
import com.lzy.product.entity.AgentProduct;
import com.lzy.product.service.AgentProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AgentProductServiceImpl implements AgentProductService {

    @Autowired
    AgentProductMapperExt agentProductMapperExt;

    public PageInfo<AgentProductDto> queryAgentProductList(Pager pager, AgentProductDto paramDto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<AgentProductDto> list = agentProductMapperExt.queryAgentProductList(paramDto);
        return new PageInfo<>(list);
    }

    @Override
    public Boolean deleteAagntProductList(String ids) {
        return agentProductMapperExt.deleteAagntProductList(ids);
    }

    @Override
    public AgentProductDto queryAgentProductById(Long id) {
        return agentProductMapperExt.queryAgentProductById(id);
    }

    @Override
    public Long createAagntProduct(AgentProductDto agentProductDto) {
        AgentProduct agentProduct = DozerUtils.map(agentProductDto, AgentProduct.class);
        return agentProductMapperExt.insertSelective(agentProduct) > 0 ? agentProduct.getId() : null;
    }


    @Override
    public Long insert(AgentProductDto dto) {
        return null;
    }

    @Override
    public Boolean update(AgentProductDto dto) {
        return agentProductMapperExt.updateByPrimaryKeySelective(DozerUtils.map(dto, AgentProduct.class))>0;
    }

    @Override
    public Boolean delete(Long id) {
        return agentProductMapperExt.deleteByPrimaryKey(id) > 0;
    }

    @Override
    public Boolean remove(Long id) {
        AgentProductDto agentProductDto = agentProductMapperExt.queryAgentProductById(id);
        agentProductDto.setDeleted(true);
        return agentProductMapperExt.updateByPrimaryKeySelective(DozerUtils.map(agentProductDto, AgentProduct.class)) > 0;
    }
    @Override
    public PageInfo<AgentProductDto> queryAgentProductListByMobile(Pager pager, AgentProductDto paramDto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<AgentProductDto> list = agentProductMapperExt.queryAgentProductList(paramDto);
        return new PageInfo<>(list);
    }


    @Override
    public AgentProductDto findById(Long id) {
        return null;
    }

    @Override
    public List<AgentProductDto> query(AgentProductDto dto) {
        return null;
    }
}
